package tests.cases {
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	import org.flexunit.Assert;
	
	import tests.cases.DefaultTestCase;
	
	public class TestSettings extends DefaultTestCase {
		
		private var coreSystemService:RemoteObject;
		
		[Before]
		public function setUp():void {
			
			coreSystemService = new RemoteObject();
			coreSystemService.destination = "amfphp";
			coreSystemService.source = "CoreSystemService";
		}
		
		[After]
		public function tearDown():void {
			
			coreSystemService = null;
		}
		
		// ----------------------------------------------------------------
		// TEST GOOD SAVE SETTINGS
		// ----------------------------------------------------------------
		[Test(async)]
		public function testGoodSaveSettings():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user001",
				firstName: "System",
				lastName: "Administrator",
				email: "admin@test.com",
				password: "password",
				phoneNumber: "0123456789",
				description: "123",
				gender: "M",
				dateOfBirth: "2009-06-12",
				location: "",
				occupation: "",
				institution: "",
				avatarUID: "3",
				themeUID: "4"
			};
			
			var token:AsyncToken = coreSystemService.saveUserSettings(
				argsVO.sessionID, argsVO.userUID,
				argsVO.firstName, argsVO.lastName,
				argsVO.email, argsVO.password,
				argsVO.phoneNumber, argsVO.description,
				argsVO.gender,  argsVO.dateOfBirth,
				argsVO.location, argsVO.occupation, argsVO.institution,
				argsVO.avatarUID, argsVO.themeUID
			);
			runAsyncTest(token, argsVO, handleGoodSaveSuccess);
		}
		
		private function handleGoodSaveSuccess(message:ResultEvent, passedData:Object):void {
			
			Assert.assertTrue(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST BAD SAVE SETTINGS
		// ----------------------------------------------------------------
		[Test(async)]
		public function testBadSaveSettings():void {
			
			var argsVO:Object = {
				sessionID: "debug",
				userUID: "user002",
				firstName: "System",
				lastName: "Administrator",
				email: "admin@test.com",
				password: "password",
				phoneNumber: "0123456789",
				description: "123",
				gender: "M",
				dateOfBirth: "2009-06-12",
				location: "",
				occupation: "",
				institution: "",
				avatarUID: "3",
				themeUID: "4"
			};
			
			var token:AsyncToken = coreSystemService.saveUserSettings(
				argsVO.sessionID, argsVO.userUID,
				argsVO.firstName, argsVO.lastName,
				argsVO.email, argsVO.password,
				argsVO.phoneNumber, argsVO.description,
				argsVO.gender,  argsVO.dateOfBirth,
				argsVO.location, argsVO.occupation, argsVO.institution,
				argsVO.avatarUID, argsVO.themeUID
			);
			runAsyncTest(token, argsVO, handleBadSaveSuccess);
		}
		
		private function handleBadSaveSuccess(message:ResultEvent, passedData:Object):void {
			
			Assert.assertFalse(message.result);
		}
		
		// ----------------------------------------------------------------
		// TEST GET AVATAR LIST
		// ----------------------------------------------------------------
		[Test(async)]
		public function testGetAvatarList():void {
			
			var argsVO:Object = {
				sessionID: "debug"
			};
			
			var token:AsyncToken = coreSystemService.getAvatarList(argsVO.sessionID);
			runAsyncTest(token, argsVO, handleGetAvatarList);
		}
		
		private function handleGetAvatarList(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			
			Assert.assertTrue((message.result.length > 0));
		}
		
		// ----------------------------------------------------------------
		// TEST GET THEME LIST
		// ----------------------------------------------------------------
		[Test(async)]
		public function testGetThemeList():void {
			
			var argsVO:Object = {
				sessionID: "debug"
			};
			
			var token:AsyncToken = coreSystemService.getThemeList(argsVO.sessionID);
			runAsyncTest(token, argsVO, handleGetThemeList);
		}
		
		private function handleGetThemeList(message:ResultEvent, passedData:Object):void {
			
			Assert.assertNotNull(message.result);
			
			Assert.assertTrue((message.result.length > 0));
		}
	}
}